package cn.zust.edu.cn;

public class Triangle implements IShape {
    private Point ptA;
    private Point ptB;
    private Point ptC;
    private double edgeA;
    private double edgeB;
    private double edgeC;

    public Triangle(Point a, Point b, Point c) {
        ptA = new Point(a);
        ptB = new Point(b);
        ptC = new Point(c);
        edgeA = distance(b, c);
        edgeB = distance(a, c);
        edgeC = distance(a, b);
    }

    private double distance(Point p1, Point p2) {
        int dx = p1.x - p2.x;
        int dy = p1.y - p2.y;
        return Math.sqrt(dx * dx + dy * dy);
    }

    public double getEdgeA() { return edgeA; }
    public double getEdgeB() { return edgeB; }
    public double getEdgeC() { return edgeC; }

    @Override
    public double perimeter() {
        return edgeA + edgeB + edgeC;
    }

    @Override
    public double area() {
        double s = perimeter() / 2;
        return Math.sqrt(s * (s - edgeA) * (s - edgeB) * (s - edgeC));
    }

    @Override
    public void draw() {
        System.out.printf("Drawing Triangle with points (%d,%d), (%d,%d), (%d,%d)\n",
                ptA.x, ptA.y, ptB.x, ptB.y, ptC.x, ptC.y);
    }
}
